<table><tr>

<td valign='top'>
	<% if current_user.groups.count >1 %>
	<div style='margin-top:2px;padding-top:2px;'>
	  <%= !(params[:group]) ? ('<b>All groups</b>') : (link_to 'All groups', tickets_url) %> <br />
	<% current_user.groups.each do |group| %>
	   <%= (params[:group].to_i == group.id) ? ('<b>' + group.name + '</b>') : (link_to group.name, tickets_url(:group => group.id)) %><br />
	<% end %>
	</div>
	<% end %>
</td>
<td>
<% if @tickets.size > 0 %>
<table border=1>
  <tr>
 
    <th>Name</th>
    <th>Number</th>
    <th>Created at</th>
	<th>Deadline</th>
	<th>Type</th>
	<th>Group</th>

  </tr>
  
<% for ticket in @tickets %>
  <%= ticket.status ? "<tr bgcolor=#20FF20>" : (ticket.deadline < Date.today ? "<tr bgcolor='red'>" : "<tr bgcolor='yellow'>")  %>
  
    <td><%= link_to ticket.name, edit_ticket_path(ticket)  %></td>
    <td><%= ticket.number %></td>
    <td><%= ticket.created_at.to_date %></td>
    <td><%= ticket.deadline %></td>
    <td><%=h ticket.ticket_template.name %></td>
    <td><%=h ticket.group.name %></td>
    <td>
	   	<%= link_to 'Change group/Send email', change_group_ticket_path(ticket) %> 
	         <%= link_to "Close", ticket_path(ticket, :ticket=>{:group_id => "0"}), :method => :put, :confirm => "Are you sure?"%>
	          <% if current_user.admin? %>
	           <%= link_to "Destroy", ticket_path(ticket), :method => :delete, :confirm => "Are you sure?" %>
	          <% end %>
	</td>
  </tr>
<% end if @tickets%>
</table>
<% end %>
<%= link_to 'New ticket', new_ticket_path %>
</td>
<td style="vertical-align: top">
<% form_tag find_tickets_path do -%>
Number: <%= text_field_tag 'ticket_number' %>
<%= submit_tag "find" %>
<% end -%>
</td>

</tr>
</table>
